/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.os.dao.ephimov;

import  edu.os.dao.ephimov.*;
import  edu.os.dao.ephimov.interfaces.*;
import  edu.os.dao.ephimov.transferobjects.*;
import java.io.IOException;


import java.util.*;

/**
 *
 * @author shalash
 */
public class Facade {
   public DAOFactory objDAO;
   public ApplicationDAO appDAO;    
   
   public Facade() {
        objDAO = DAOFactory.getDAOFactory(DAOFactory.MEMORY);//чтение из xml
        appDAO = objDAO.getApplicationDAO();             
    }
   
   public void AddApplication() {
       Application app = new Application();
       app.setName("Need For Speed");
       app.setDiscription("Гонки");
       appDAO.addApplication(app);
   }
   
   public String[] getAllApps() throws IOException{

       List<Application> l = appDAO.getAllApplications();
       Iterator<Application> itr = l.iterator();

       String[] res = new String[l.size()];
       int count = 0;
       while (itr.hasNext()) {
           
           Application a = itr.next();
           res[count] = a.getIdApplication() + " " + a.getName() +" " + a.getDiscription() + " \n";
           ++ count;
       } 
       return res;
   }
   
   public void UpdateApplication() {
       Application app = new Application();
       app.setIdApplication(2);
       
       app.setName("Microsoft Office");
       app.setDiscription("Программка создания и редактирования доков");
       new Mylogger().writeLog(new Integer(appDAO.updateApplicatoin(app)).toString());
   }
      
}
